﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.models.world.vos.actors.machines {
    import flash.events.*;
    import flash.geom.*;
    import net.wooga.pets.events.*;
    import __AS3__.vec.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.constants.*;
    import com.adobe.utils.*;

    public class EntranceMachineVO extends AbstractMachineVO {

        private const PETS_VISIBLE_IN_QUE:int = 6;
        private const PIXELS_BETWEEN_PETS_IN_QUE:int = 128;
        private const MOST_RIGHT_POSITION_IN_QUE:int = 640;
        private const BASE_Y_POSITION:int = -100;

        private var pet_ids_queed_pool:Array;

        public function EntranceMachineVO(_arg1:Object, _arg2:IEventDispatcher){
            this.pet_ids_queed_pool = [];
            super(_arg1, _arg2);
        }
        override public function handlePatient(_arg1:ITreatable):void{
            var _local2:InfoEvent;
            dispatch(new InfoEvent(EventConstants.DISABLE_VIEW, _arg1.id));
            if (_arg1.state == WorldConstants.CURED){
                dispatch(new InfoEvent(EventConstants.REMOVE_PATIENT, _arg1.id, _arg1));
                if (_arg1.diseaseName == WorldConstants.DISEASE_OLD){
                    dispatch(new Event(EventConstants.SHOW_FIREWORK));
                };
                if (!_arg1.dismissed){
                    _local2 = new InfoEvent(EventConstants.DISMISS_CURED_PATIENT, _arg1.id, _arg1);
                    dispatch(_local2);
                    _arg1.dismissed = true;
                    _arg1 = null;
                };
            } else {
                if (_arg1.targetType == null){
                    dispatch(new InfoEvent(EventConstants.DISPATCH_SEND_AMBULANCE_AWAY, _arg1.diseaseName));
                    _arg1.checkMove();
                } else {
                    if (_arg1.targetType == type){
                        if (this.addPetIdToQue(_arg1.id)){
                            this.dispatchUpdatedPetsPositions();
                        };
                    };
                };
            };
        }
        override public function handleBaby(_arg1:IBaby, _arg2:Boolean):void{
            var _local3:InfoEvent;
            dispatch(new InfoEvent(EventConstants.DISABLE_VIEW, _arg1.id));
            if (!_arg1.dismissed){
                _local3 = new InfoEvent(EventConstants.DISMISS_CURED_PATIENT, _arg1.id, _arg1);
                dispatch(_local3);
            };
            dispatch(new Event(EventConstants.SHOW_FIREWORK));
            dispatch(new InfoEvent(EventConstants.REMOVE_PATIENT, _arg1.id, _arg1));
        }
        public function addPetIdToQue(_arg1:String):Boolean{
            if (!ArrayUtil.arrayContainsValue(this.pet_ids_queed_pool, _arg1)){
                this.pet_ids_queed_pool.push(_arg1);
                return (true);
            };
            return (false);
        }
        public function removePetIdFromQue(_arg1:String):void{
            if (ArrayUtil.arrayContainsValue(this.pet_ids_queed_pool, _arg1)){
                ArrayUtil.removeValueFromArray(this.pet_ids_queed_pool, _arg1);
            };
        }
        public function dispatchUpdatedPetsPositions():void{
            var _local3:Vector.<Point>;
            var _local1:int;
            var _local2:String = this.pet_ids_queed_pool[_local1];
            while ((((_local1 < this.PETS_VISIBLE_IN_QUE)) && (!((_local2 == null))))) {
                _local3 = this.createEndPoint(_local1);
                dispatch(new InfoEvent(EventConstants.MOVE_TO_POSITION, _local2, _local3));
                ++_local1;
                _local2 = this.pet_ids_queed_pool[_local1];
            };
        }
        private function createEndPoint(_arg1:int):Vector.<Point>{
            var _local2 = 1;
            var _local3:Vector.<Point> = new Vector.<Point>(_local2);
            _local3[0] = new Point(this.getXPositionBasedOnPositionInQue(_arg1), this.BASE_Y_POSITION);
            return (_local3);
        }
        private function getXPositionBasedOnPositionInQue(_arg1:int):int{
            return ((this.MOST_RIGHT_POSITION_IN_QUE - (this.PIXELS_BETWEEN_PETS_IN_QUE * _arg1)));
        }
        override public function destroy():void{
            this.pet_ids_queed_pool = [];
            super.destroy();
        }

    }
}//package net.wooga.pets.models.world.vos.actors.machines 
